public class num169 {
    //多数元素--摩尔投票
    public int majorityElement(int[] nums) {
        int count = 1;
        int ans = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if(ans == nums[i]) {
                count ++;
            }else {
                count --;
            }
            if(count == 0) {
                count = 1;
                ans = nums[i];
            }
        }
        return ans;
    }
}
